package cn.izeno.wx.aes

/**
 * Aes 解密时遇到异常 [java.security.InvalidKeyException: Illegal key size](https://blog.csdn.net/wangjunjun2008/article/details/50847426)
 * > 下载地址：  [JDK6](http://www.oracle.com/technetwork/java/javase/downloads/jce-6-download-429243.html)  [JDK7](http://www.oracle.com/technetwork/java/javase/downloads/jce-7-download-432124.html)  [JDK8](http://www.oracle.com/technetwork/java/javase/downloads/jce8-download-2133166.html)
 * >
 * >  下载包的readme.txt 有安装说明，即替换
 * >
 * > ${jdk_home}/jre/lib/security
 * >
 * > ${jre_home}/lib/security
 * >
 * > 目录下的 local_policy.jar 和 US_export_policy.jar 文件。
 */
class AesException internal constructor(
    //public final static int EncodeBase64Error = -40009;
    //public final static int DecodeBase64Error = -40010;
    //public final static int GenReturnXmlError = -40011;

    val code: Int) : Exception(getMessage(code)) {
  companion object {

    val OK = 0
    val ValidateSignatureError = -40001
    val ParseXmlError = -40002
    val ComputeSignatureError = -40003
    val IllegalAesKey = -40004
    val ValidateAppidError = -40005
    val EncryptAESError = -40006
    val DecryptAESError = -40007
    val IllegalBuffer = -40008

    private fun getMessage(code: Int): String? {
      when (code) {
        ValidateSignatureError -> return "签名验证错误"
        ParseXmlError -> return "xml解析失败"
        ComputeSignatureError -> return "sha加密生成签名失败"
        IllegalAesKey -> return "SymmetricKey非法"
        ValidateAppidError -> return "appid校验失败"
        EncryptAESError -> return "aes加密失败"
        DecryptAESError -> return "aes解密失败"
        IllegalBuffer -> return "解密后得到的buffer非法"
        //		case EncodeBase64Error:
        //			return "base64加密错误";
        //		case DecodeBase64Error:
        //			return "base64解密错误";
        //		case GenReturnXmlError:
        //			return "xml生成失败";
        else -> return null // cannot be
      }
    }
  }

}
